import 'package:flutter/material.dart';
import 'package:xws/models/goods/goods_obj.dart';
import 'package:xws/models/notify/chat_obj.dart';
import 'package:xws/utils/app_util.dart';
import 'package:xws/utils/dio_utils/request/user_req.dart';

import 'chat_page.dart';

/// 开始一个会话
Future<void> startChat(
  BuildContext context,
  GoodsObj goodsObj,
) async {
  loading(context);
  final ChatObj? co = await createChat(goodsObj.user.id, goodsObj.id);
  close(context);

  if (co == null) return;

  await enterChatRoom(context, co);
}

/// 进入聊天室
Future<void> enterChatRoom(
  BuildContext context,
  ChatObj chatObj, {
  void Function(int)? unreadCallback,
}) async {
  await push(
      context,
      ChatPage(
        chatObj: chatObj,
        unreadCallback: unreadCallback,
      ));
}
